// --------------------------------------------------------------------------------------------------------------------
// <copyright file="MetricsResultMessage.cs" company="Microsoft Corporation">
// The MIT License (MIT)
// 
// Copyright (c) 2014, Microsoft Corporation
// 
// Permission is hereby granted, free of charge, to any person obtaining a copy
//  of this software and associated documentation files (the "Software"), to deal
//  in the Software without restriction, including without limitation the rights
//  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//  copies of the Software, and to permit persons to whom the Software is
//  furnished to do so, subject to the following conditions:
// 
// The above copyright notice and this permission notice shall be included in
//  all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//  THE SOFTWARE.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------
namespace Test.Robotics.Metrics
{
    using System;
    using Microsoft.Robotics.Runtime;

    /// <summary>
    /// Represents the results of a metrics calculation, e.g. the accuracy and precision versus ground truth data
    /// See http://en.wikipedia.org/wiki/Accuracy_and_precision for details.
    /// </summary>
    public class MetricsResultMessage : AgentMessage
    {
        /// <summary>
        /// Initializes a new instance of the MetricsResultMessage class, for a successful measurement.
        /// </summary>
        /// <param name="type">The value measured (e.g. position).</param>
        /// <param name="groundTruthId">The id of the ground truth marker we are comparing with. Usually the sequence number of the ground truth message.</param>
        /// <param name="accuracy">The mean of the estimate</param>
        /// <param name="precision">The variance of the estimate</param>
        /// <param name="weight">The weight to assign to this result, if more than one result per run is reported</param>
        /// <param name="debugData">Custom debug data to include with this result</param>
        /// <param name="duration">The span of execution time measured by this metric result</param>
        /// <param name="robot">The name of the robot used, if any</param>
        /// <param name="runId">The id of the iteration that generated this message. Used to tie all messages from the same run together.</param>
        /// <param name="originatingMessage">The message that triggered the creation of this one.</param>
        /// <param name="isFinalMessage">Indicates if this is the final metrics message</param>
        public MetricsResultMessage(string type, long groundTruthId, double accuracy, double precision, double weight, string debugData, long duration, string robot, long runId, AgentMessage originatingMessage, bool isFinalMessage = false)
            : base(originatingMessage)
        {
            this.Accuracy = accuracy;
            this.Precision = precision;
            this.Weight = weight;
            this.DebugData = debugData;
            this.Duration = duration;
            this.Robot = robot;
            this.Type = type;
            this.GroundTruthId = groundTruthId;
            this.RunId = runId;
            this.IsFinalMessage = isFinalMessage;
        }

        /// <summary>
        /// Gets the id of the ground truth marker we are comparing against
        /// </summary>
        public long GroundTruthId
        {
            get;
            private set;
        }

        /// <summary>
        /// Gets the measured accuracy based on ground truth.
        /// </summary>
        public double Accuracy
        { 
            get; private set; 
        }

        /// <summary>
        /// Gets the measured  precision based on ground truth.
        /// </summary>
        public double Precision
        {
            get;
            private set;
        }

        /// <summary>
        /// Gets the weight to give this result, if it's a partial result
        /// </summary>
        public double Weight
        {
            get;
            private set;
        }

        /// <summary>
        /// Gets the additional info useful in debugging.
        /// </summary>
        public string DebugData
        {
            get;
            private set;
        }

        /// <summary>
        /// Gets the length of the period covered by this measurement, in ms. (typically the time from the last message of the same type).
        /// </summary>
        public long Duration
        {
            get;
            private set;
        }

        /// <summary>
        /// Gets the name of the robot the test was executed on, if any.
        /// </summary>
        public string Robot
        {
            get;
            private set;
        }

        /// <summary>
        /// Gets the type of metric described by this message (e.g. position, orientation)
        /// </summary>
        public string Type
        {
            get;
            private set;
        }

        /// <summary>
        /// Gets the id of the iteration that generated this message. Used to tie all messages from the same run together.
        /// </summary>
        public long RunId
        {
            get;
            private set;
        }

        /// <summary>
        /// Gets a value indicating whether this is the final message.
        /// </summary>
        public bool IsFinalMessage
        {
            get;
            private set;
        }
    }
}
